﻿#region Using Directives

using System;
using System.Web.Caching;
using System.Web.Security;
using System.Collections.Generic;

using QuickDev.Common.Utils;
using QuickDev.Common.Caching.Manager;

using QuickDev.Model;
using QuickDev.SQLServerDAL;

#endregion

namespace QuickDev.Caching
{
    /// <summary>
    /// Cache Layer For dbo.OPM_ReturnType.
    /// </summary>
    public class ReturnTypeCache
    {
        #region Constants

        private const string ReturnTypeModelCacheKey = "_ReturnType_CacheKey_{0}";
        private const string ReturnTypeCollectionCacheKey = "_ReturnType_Collection_{0}";

        #endregion

        #region Refresh Cache

        /// <summary>
        /// Refreshes the collection in the cache.
        /// This will make that the collection should reinsert itself on the next page request
        /// </summary>
        public static void RemoveAllCollectionFromCache()
        {
            CacheHelper.RemoveAllCacheObjectStartWith( ReturnTypeCollectionCacheKey.Substring( 0 , ReturnTypeCollectionCacheKey.LastIndexOf( "_Collection_" ) + "_Collection_".Length ) );
        }

        /// <summary>
        /// Removes the Object Info from the cache.
        /// This will make that the Object should reinsert itself on the next page request
        /// </summary>
        /// <param name="key">The key.</param>
        public static void RemoveModelFromCache( int id )
        {
            CacheHelper.RemoveCacheObject<string>( string.Format( ReturnTypeModelCacheKey , id ) );
        }

        #endregion

        #region ReturnTypeCache.GetModel( int id ) Method

        /// <summary>
        /// public ReturnType GetModel( int id )
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>ReturnType model</returns>
        public static ReturnType GetModel( int id )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.Caching.ReturnTypeCache.GetModel -- id " );

            return CacheHelper.CacheObject<ReturnType>
            (
                delegate
                {
                    return ReturnTypeDAL.GetModel( id );
                } ,
                string.Format( ReturnTypeModelCacheKey , id ) ,
                CacheLength.GetLongCacheTime ,
                CacheItemPriority.High
            );
        }
        #endregion

        #region ReturnTypeCache.GetList( bool showHidden ) Method

        /// <summary>
        /// public List(ReturnType) GetList( bool showHidden )
        /// </summary>
        /// <param name="showHidden">showHidden</param>
        /// <returns>List(ReturnType)</returns>
        public static List<ReturnType> GetList( bool showHidden )
        {
            return CacheHelper.CacheObject<List<ReturnType>>
            (
                delegate
                {
                    return ReturnTypeDAL.GetList( showHidden , false );
                } ,
                string.Format( ReturnTypeCollectionCacheKey , showHidden ) ,
                CacheLength.GetLongCacheTime ,
                CacheItemPriority.High
            );
        }
        #endregion

        #region ReturnTypeCache.GetList( bool showHidden , bool showDeleted ) Method

        /// <summary>
        /// public List(ReturnType) GetList( bool showHidden , bool showDeleted )
        /// </summary>
        /// <param name="showHidden">showHidden</param>
        /// <param name="showDeleted">showDeleted</param>
        /// <returns>List(ReturnType)</returns>
        public static List<ReturnType> GetList( bool showHidden , bool showDeleted )
        {
            return ReturnTypeDAL.GetList( showHidden , showDeleted );
        }
        #endregion
    }
}

